package com.example.controller;


import com.example.pojo.Brand;
import com.example.pojo.Customer;
import com.example.pojo.PageBean;
import com.example.tools.JwtUtils;
import com.example.tools.Result;
import com.example.service.impl.CustomerServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@Slf4j
public class CustomerController {
    @Autowired
    private CustomerServiceImpl customerService;

    /**
     * 获取个人信息
     *
     * @return
     */
    @GetMapping("/getInfo")
    public Result getCustomer(@RequestHeader("Token") String token) {
        String s = JwtUtils.parseJWT(token).get("cusCode", String.class);

        Integer cusCode = Integer.parseInt(s);
        Customer customer=customerService.getCustomerById(cusCode);
        return Result.success(customer);
    }


    /**
     * 跟新
     *
     * @param customer
     * @return
     */
    @PostMapping("/admin/updateCustomer")
    public Result updateCustomer(@RequestBody Customer customer) {
        customerService.updateCustomer(customer);
        return Result.success();
    }

    /**
     * 注册
     *
     * @return
     */
    @PostMapping("/admin/addCustomer")
    public Result addCustomer(@RequestBody Customer customer) {
        customerService.addCustomer(customer);
        return Result.success();
    }


}
